package leetcode.editor.cn.q0xx

class Q28 {
    fun strStr(haystack: String, needle: String): Int {
        if (needle.isEmpty()) return 0
        if (haystack.length < needle.length) return -1

        val ca1 = haystack.toCharArray()
        val ca2 = needle.toCharArray()

        for (i in 0..(haystack.length - needle.length)) {
            var match = false
            for (j in ca2.indices) {
                match = ca1[i + j] == ca2[j]
                if (!match) {
                    break
                }
            }
            if (match) {
                return i
            }
        }

        return -1
    }
}